package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisManageRightMenu;
import com.hunttown.mes.rpc.domain.AnalysisManageRightMenuDTO;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import com.hunttown.mes.rpc.exception.ConvertException;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:05:40
 */
public class AnalysisManageRightMenuConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisManageRightMenuConverts.class);

    public static List<AnalysisManageRightMenuDTO> convert(List<AnalysisManageRightMenu> analysisManageRightMenuList) {
        if (CollectionUtils.isEmpty(analysisManageRightMenuList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisManageRightMenuDTO> analysisManageRightMenuListResult = Lists.newArrayList();
        for (AnalysisManageRightMenu analysisManageRightMenu : analysisManageRightMenuList) {
            analysisManageRightMenuListResult.add(convert(analysisManageRightMenu));
        }
        return analysisManageRightMenuListResult;
    }

    public static AnalysisManageRightMenuDTO convert(AnalysisManageRightMenu analysisManageRightMenu) {
        try {
            return BeanUtils.copy(analysisManageRightMenu, AnalysisManageRightMenuDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightMenu到AnalysisManageRightMenuDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightMenu到AnalysisManageRightMenuDTO转换失败", e);
        }
    }

    public static AnalysisManageRightMenu convert(AnalysisManageRightMenuDTO analysisManageRightMenuDTO) {
        try {
            return BeanUtils.copy(analysisManageRightMenuDTO, AnalysisManageRightMenu.class);
        } catch (Exception e) {
            LOG.error("AnalysisManageRightMenuDTO到AnalysisManageRightMenu转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisManageRightMenuDTO到AnalysisManageRightMenu转换失败", e);
        }
    }
}